import 'package:flutter/material.dart';
import '../../services/database_helper.dart';
import '../../core/snackbar_helper.dart';

class DatabaseToolsScreen extends StatelessWidget {
  const DatabaseToolsScreen({super.key});

  Future<void> _resetDatabase(BuildContext context) async {
    try {
      final dbHelper = DatabaseHelper();
      await dbHelper.resetDatabase();
      SnackbarHelper.showSuccess(context, '数据库重置成功，请重启应用');
    } catch (e) {
      SnackbarHelper.showError(context, '重置失败: $e');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('数据库工具'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          children: [
            Card(
              child: ListTile(
                leading: const Icon(Icons.refresh, color: Colors.orange),
                title: const Text('重置数据库'),
                subtitle: const Text('删除所有数据并重新创建表结构'),
                trailing: ElevatedButton(
                  onPressed: () => _resetDatabase(context),
                  style: ElevatedButton.styleFrom(
                    backgroundColor: Colors.orange,
                  ),
                  child: const Text('重置', style: TextStyle(color: Colors.white)),
                ),
              ),
            ),
            const SizedBox(height: 16),
            const Card(
              child: ListTile(
                leading: Icon(Icons.info, color: Colors.blue),
                title: Text('数据库信息'),
                subtitle: Text('版本: 2\n表: restaurants, products'),
              ),
            ),
          ],
        ),
      ),
    );
  }
}